package cn.iocoder.yudao.module.contract.dal.mysql.exportContract;

import java.util.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.MPJLambdaWrapperX;
import cn.iocoder.yudao.module.contract.dal.dataobject.exportContract.ExportContractDO;
import cn.iocoder.yudao.module.contract.dal.dataobject.invoiceContract.InvoiceContractDO;
import cn.iocoder.yudao.module.contract.dal.dataobject.order.OrderDO;
import cn.iocoder.yudao.module.contract.utils.StringUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.contract.controller.admin.exportContract.vo.*;

/**
 * 出口合同 Mapper
 *
 * @author 管理员
 */
@Mapper
public interface ExportContractMapper extends BaseMapperX<ExportContractDO> {

    default PageResult<ExportContractDO> selectPage(ExportContractPageReqVO reqVO) {
        return selectPage(reqVO, new MPJLambdaWrapperX<ExportContractDO>()
                .eqIfPresent(ExportContractDO::getType, reqVO.getType())
                .betweenIfPresent(ExportContractDO::getCreateTime, reqVO.getCreateTime())
                .betweenIfPresent(ExportContractDO::getAudat, reqVO.getAudat())

                .in(!ObjectUtils.isEmpty(reqVO.getStatusList()), ExportContractDO::getStatus, Arrays.asList(!ObjectUtils.isEmpty(reqVO.getStatusList())?reqVO.getStatusList():new Object[]{""}))


                .like(!ObjectUtils.isEmpty(reqVO.getVkorg()) && "1".equals(reqVO.getVkorgType()),ExportContractDO::getVkorg, reqVO.getVkorg())
                .in(!ObjectUtils.isEmpty(reqVO.getVkorg()) && "2".equals(reqVO.getVkorgType()),ExportContractDO::getVkorg, !ObjectUtils.isEmpty(reqVO.getVkorg()) ?reqVO.getVkorg().split(","): new Object[]{""})

                .like(!ObjectUtils.isEmpty(reqVO.getBstnk()) && "1".equals(reqVO.getBstnkType()),ExportContractDO::getBstnk, reqVO.getBstnk())
                .in(!ObjectUtils.isEmpty(reqVO.getBstnk()) && "2".equals(reqVO.getBstnkType()),ExportContractDO::getBstnk, !ObjectUtils.isEmpty(reqVO.getBstnk()) ?reqVO.getBstnk().split(","): new Object[]{""})


                .like(!ObjectUtils.isEmpty(reqVO.getCreatorUsername()) && "1".equals(reqVO.getCreatorUsernameType()),ExportContractDO::getCreatorUsername, reqVO.getCreatorUsername())
                .in(!ObjectUtils.isEmpty(reqVO.getCreatorUsername()) && "2".equals(reqVO.getCreatorUsernameType()),ExportContractDO::getCreatorUsername, !ObjectUtils.isEmpty(reqVO.getCreatorUsername()) ?reqVO.getCreatorUsername().split(","): new Object[]{""})

                .orderByDesc(ObjectUtils.isEmpty(reqVO.getOrder()), ExportContractDO::getAudat).orderByDesc(ObjectUtils.isEmpty(reqVO.getOrder()),ExportContractDO::getBstnk)
                .orderBy(ObjectUtils.isNotEmpty(reqVO.getOrder()),"ascending".equals(reqVO.getOrder()), StringUtils.toUnderScoreCase(reqVO.getProp()))
        );
    }

}